package com.crazy.base.common.utils.context;

import java.util.HashMap;
import java.util.Map;

public class ContextUtil {

    private final static ThreadLocal<Map<String, Object>> contextHolder = ThreadLocal.withInitial(HashMap::new);

    public <T> void set(String key, T value) {
        contextHolder.get().put(key, value);
    }

    @SuppressWarnings("unchecked")
    public <T> T get(String key) {
        return (T) contextHolder.get().get(key);
    }

    public void remove(String key) {
        contextHolder.get().remove(key);
    }

    public void clear() {
        contextHolder.get().clear();
    }
}
